package com.gjl.lean;

import java.util.Scanner;

public class BubbleSort {
    public static void main(String[] args) {
        int arr[] = new int[6];
        Scanner input = new Scanner(System.in);
        for (int x = 0; x < arr.length; x++) {
            System.out.println("请依次输入需要排序的数组数字：");
            int num = input.nextInt();
            arr[x] = num;
        }
        System.out.println("排序前数组为：");
        for (int y : arr) {
            System.out.print(y + " ");
        }

        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
        System.out.println();
        System.out.println("排序后数组为：");
        for (int num : arr) {
            System.out.print(num + " ");
        }
    }
}
